package demo.controller;

import demo.Constants.PermissionConstant;
import demo.annotation.RequiredPermissions;
import demo.entity.employees;
import demo.entity.managers;
import demo.entity.record;
import demo.service.CommonService;
import demo.service.HigherService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Permissions;
import java.util.List;

@RestController
@RequestMapping(path="/higher")
public class HigherController {
    private Logger logger = Logger.getLogger(HigherController.class);

    @Autowired
    private HigherService higherService;
    private CommonService commonService;

    public HigherController(CommonService commonService) {
        this.commonService = commonService;
    }

    @GetMapping("/queryAllEmployees")
    @RequiredPermissions(PermissionConstant.HIGHER)
    List<employees> queryAllEmployees(@RequestParam(value = "emp_id")int emp_id) {
        logger.info(": 查询工号为 " + emp_id + " 的员工信息");
        return higherService.queryAllEmployees(emp_id);
    }
    @PutMapping("/changeBasic_Salary")
    @RequiredPermissions(PermissionConstant.HIGHER)
    employees changeBasic_Salary(@RequestParam(value = "emp_id")int emp_id , @RequestParam(value = "target_id")int target_id,@RequestParam(value = "newValue")int newBasic_Salary ){
        logger.info(": 更改工号为 " + emp_id + " 的员工的基础工资为 " + newBasic_Salary);
        return  higherService.changeBasic_Salary(emp_id,target_id,newBasic_Salary);
    }
    @PutMapping("/changeMonthly_Salary")
    @RequiredPermissions(PermissionConstant.HIGHER)
    employees changeMonthly_Salary(@RequestParam(value = "emp_id")int emp_id ,@RequestParam(value = "target_id")int target_id,@RequestParam(value = "newValue")int newMonthly_Salary ){
        logger.info(": 更改工号为 " + emp_id + " 的员工的当月工资为 " + newMonthly_Salary);
        return  higherService.changeMonthly_Salary(emp_id,target_id,newMonthly_Salary);
    }
    @PutMapping("/changeArrival_time")
    @RequiredPermissions(PermissionConstant.HIGHER)
    employees changeArrival_time(@RequestParam(value = "emp_id")int emp_id ,@RequestParam(value = "target_id")int target_id,@RequestParam(value = "newValue")String newArrival_time ){
        logger.info(": 更改工号为 " + emp_id + " 的员工的应到岗时间为 " + newArrival_time);
        return  higherService.changeArrival_time(emp_id,target_id,newArrival_time);
    }
    @PutMapping("/changeDeparture_time")
    @RequiredPermissions(PermissionConstant.HIGHER)
    employees changeDeparture_time(@RequestParam(value = "emp_id")int emp_id ,@RequestParam(value = "target_id")int target_id,@RequestParam(value = "newValue")String newDeparture_time ){
        logger.info(": 更改工号为 " + emp_id + " 的员工的应离岗时间为 " + newDeparture_time);
        return  higherService.changeDeparture_time(emp_id,target_id,newDeparture_time);
    }
    @PutMapping("/changeRestholiday")
    @RequiredPermissions(PermissionConstant.HIGHER)
    employees changeRestholiday(@RequestParam(value = "emp_id")int emp_id ,@RequestParam(value = "target_id")int target_id,@RequestParam(value = "newValue")int newRestholiday ){
        logger.info(": 更改工号为 " + emp_id + " 的员工的假期为 " + newRestholiday);
        return  higherService.changeRestHoliday(target_id,newRestholiday);
    }
    @GetMapping("/queryRecord") //查询某人打卡记录
    @RequiredPermissions(PermissionConstant.HIGHER)
    List<record> queryRecord(@RequestParam(value = "emp_id")int emp_id) {
        logger.info("：查询工号为 " + emp_id + " 的员工的打卡记录");
        return commonService.queryRecord(emp_id);
    }
    @GetMapping("/queryAllRecord") //查询该经理所在部门所有人打卡记录
    @RequiredPermissions(PermissionConstant.HIGHER)
    List<record> queryAllRecord(@RequestParam(value = "emp_id")int emp_id) {
        logger.info("：查询工号为 " + emp_id + " 的经理所在部门所有人打卡记录");
        return higherService.queryAllRecord(emp_id);
    }
    @PostMapping("/addManagers")  //提交请假申请
    @RequiredPermissions(PermissionConstant.HIGHER)
    managers addManagers(@RequestBody managers man) {
        int emp_id = man.getEmp_id();
        logger.info("：工号为 " + emp_id + " 的员工提交请假申请");
        return higherService.addManagers(man);
    }
    @GetMapping("/queryManagers") //只能查自己部门请假记录
    @RequiredPermissions(PermissionConstant.HIGHER)
    List<managers> queryManagers(@RequestParam(value = "emp_id")int emp_id) {
        logger.info("：查询工号为 " + emp_id + " 的员工所在部门请假申请");
        return higherService.queryManagers(emp_id);
    }
    @GetMapping("/queryManagersById")
    @RequiredPermissions(PermissionConstant.HIGHER)
    managers queryManagersById(@RequestParam(value = "emp_id")int emp_id,@RequestParam(value = "target_id")int target_id) {
        logger.info("：查询工号为 " + emp_id + " 的员工的请假申请");
        return higherService.queryManagersById(emp_id,target_id);
    }
    @PutMapping("/dealManagers")
    @RequiredPermissions(PermissionConstant.HIGHER)
    managers dealManagers(@RequestParam(value = "emp_id")int emp_id,@RequestParam(value = "id")int id ,@RequestParam(value = "status")String status ){
        logger.info("：批复工号为 " + emp_id + " 的员工的请假申请并且批复结果为 " + status);
        return  higherService.dealManagers(emp_id,id,status);
    }

}
